<?php 
namespace town\controller;

use town\base\Store;
use town\model\Tags;
use town\model\Post;
use town\dmod\DB;

class HomeController
{

	/**
	 * 显示主页
	 */
	public function index()
	{
		// 1.获取最新的一篇文章
		$postID = DB::table('posts')->orderBy('id', 'DESC')->value('id');
		$post   = (new Post)->postById($postID);
		$html   = strip_tags($post['content_html']);
		$post['content_html'] = mb_substr($html, 0, 155, 'utf-8');

		// 2.获取最近的10篇文章
		$list = DB::table('posts')->orderBy('id', 'DESC')->limit('1,10')
			->fields(['id', 'title', 'create_at'])->get();
		foreach ($list as $key => &$value) {
			$value['create_at'] = date('Y/m/d', $value['create_at']);
		}


		// 3.获取 tags
		$tags = (new Tags)->dict();


		// 4.获取网站信息

		// 5.显示数据
		$data = [
			'tags' => $tags,
			'post' => $post,
			'list' => $list
		];
		return view('home/home', $data);
	}

}
